<?php namespace app\home\controller;



class Content extends Marster{
    //动作
    public function index($aid=null){
    //此处书写代码...
//        取出文章内容和文章标题  文章表和 文章内容表
            $articleData=Db::table('article')
                ->join('article_data','aid','=','article_aid')
                ->where('article.aid',$aid)->get();
//        p($articleData);die;
                View::with('articleData',$articleData);
//        根据时间排序找到最新文章标题
        $ctitle=Db::table('article')->orderBy('sendtime','DESC')->orderBy('aid','ASC')->limit(4)->get(['ctitle','sendtime','aid']);
//        p($ctitle);die;
        View::with('ctitle',$ctitle);
//       文章表和分类表 获得当前文章的分类
        $article_catgory=Db::table('article')->join('category','cid','=','category_cid')->limit(4)->get(['ctitle','aid','cname','thumb']);
//        p($article_catgory);die;
        View::with('article_catgory',$article_catgory);

//        需要获得文章标签 和文章名称
        $articleTitle=Db::table('article')->get(['ctitle','aid']);
        foreach($articleTitle as $k=>$v){
            $articleTitle[$k]['tag']=Db::table('tag')
                ->join('article_tag','tag_tid','=','tid')
                ->join('article','aid','=','article_aid')
                ->where('article_tag.article_aid',$v['aid'])
                ->get(['tname','tid']);
        }
//        p($articleTitle);die;
        View::with('articleTitle',$articleTitle);
//        分类列表
//        $category=Db::table('category')->rand(4)->get();
        $category=   Db::query("select * from hd_category ORDER BY rand() limit 4 ");

        View::with('category',$category);
//        p($ctitle);die;
        return view();
    }
}
